# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :get_allure.py
# @Time      :2025/5/6 17:23:47
# @Author    :flower


from util.get_file import GetFile
from dataclasses import dataclass


# 定义值对象
@dataclass(frozen=True)
class AllureResult:
    case_all: int
    case_fail: int
    case_pass: int
    case_rate: float


class GetAllure:

    @staticmethod
    def get_allure():
        file_path = 'summary.json'
        base_path = '../tests/allure-reports/widgets/'
        data = GetFile.read_json_file(file_path, base_path=base_path)
        case_json = data['statistic']
        case_all = case_json['total']  # 测试用例总数
        case_fail = case_json['failed']  # 失败用例数量
        case_pass = case_json['passed']  # 成功用例数量
        if case_all >= 0:
            # 计算出来用例执行成功率
            case_rate = round((case_pass / case_all) * 100, 2)
        else:
            case_rate = 0
        return AllureResult(case_all=case_all, case_pass=case_pass, case_fail=case_fail, case_rate=case_rate)


if __name__ == "__main__":
    pass
